/**
 * @author LKQ
 * @date 2022/1/7 11:14
 * @description 贪心
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {2, 3, 1, 2, 4, 2, 3};
        solution.jump(nums);
    }

    public int jump(int[] nums) {
        int length = nums.length;
        // 上次能跳到的最远位置
        int end = 0;
        // 目前能跳到的最远位置
        int maxPosition = 0;
        int steps = 0;
        for (int i = 0; i < length - 1; i++) {
            maxPosition = Math.max(maxPosition, i + nums[i]);
            if (i == end) {
                end = maxPosition;
                steps++;
            }
        }
        return steps;
    }
}
